home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / Advanced I⁄O v2.3 / Advanced i⁄o / arithm_modadh.h < prev    next >
Text File  |  1995-06-28  |  3KB  |  90 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. /*
  3.  ************************************************************************
  4.  *
  5.  *                    Arithmetic Coding
  6.  *          Adaptive Histogram-based model for the source of data
  7.  *
  8.  * This is an extension over the basic Input_Data_Model for an adaptive
  9.  * model of the input source, which, however, uses the histogram to
  10.  * find out which symbols are expected to come out and how often. This
  11.  * is to get around the flaw of the simple AdaptiveModel, which wastes
  12.  * the probability space by assigning the frequency count 1 to a lot
  13.  * of symbols that might appear but never show up in the reality. 
  14.  * E.g., in coding the Laplacian pyramid of typical images, the
  15.  * node value of the pyramid lies in the interval [-255,255].
  16.  * The simple AdaptiveModel assigns all the possible symbols
  17.  * (511 symbols) the frequency count at least 1. Though, it turns out
  18.  * that there are only about 130 distinct values of the pyramid nodes.
  19.  * I.e. only 130/511 of the probability space is made use of.
  20.  * Except that modification, the functionality of the present model is 
  21.  * very similar to that of the AdaptiveModel.
  22.  *
  23.  * The program assumes the total no. of distinct input symbols
  24.  * (integers) is relatively small, so simple linear arrays can be used
  25.  * for storing and looking up the frequency tables. 
  26.  *
  27.  * $Id: arithm_modadh.h,v 2.0 1995/02/07 19:37:05 oleg Exp oleg $
  28.  *
  29.  ************************************************************************
  30.  */
  31.  
  32. #ifndef __GNUC__
  33. #pragma once
  34. #endif
  35.  
  36. #ifndef _arithm_modadh_h
  37. #define _arithm_modadh_h
  38.  
  39. #ifdef __GNUC__
  40. #pragma interface
  41. #endif
  42.  
  43. #include "arithm.h"
  44. #include "histogram.h"
  45.  
  46. class AdaptiveHistModel : public Input_Data_Model
  47. {
  48.   Symbol symbol_lwb;            // Region potential input symbols
  49.   Symbol symbol_upb;            // are expected in
  50.   int no_potential_symbols;        // which are expected to occur
  51.   int no_distinct_symbols;        // which have occurred
  52.  
  53.   int update_inc;        // Increment to update freq counts by during
  54.                   // adaptation
  55.   
  56.   Index  * symbol_to_index;    // Symbol-to-index conversion
  57.   Symbol * index_to_symbol;    // Conversion from symbol index to symbol value
  58.  
  59.   void initialize_model(const Histogram& histogram);
  60.   void initial_distribution(void);    // Assign initial pdf
  61.  
  62. public:
  63.                     // Construct a model for a given
  64.                     // histogram
  65.   AdaptiveHistModel(const Histogram& histogram);
  66.   AdaptiveHistModel(void);        // With parameters are assumed to
  67.                     // be read in
  68.   virtual ~AdaptiveHistModel(void);
  69.  
  70.                     // Write out/Read in the histogram
  71.                     // to/from the coded stream
  72.   void open(BitIn& file);
  73.   void open(BitOut& file);
  74.  
  75.                     // Update the model to account 
  76.                     // for a symbol
  77.   void update_model(const Index index);
  78.  
  79.                     // Scale the accumulated statistics
  80.                     // down in anticipation of a change
  81.   void scale_down_past(void);
  82.  
  83.                     // Return the index of a symbol
  84.   Index  get_index(const Symbol symbol) const;
  85.                     // and the symbol for an index
  86.   Symbol get_symbol(const Index index) const;
  87. };
  88.  
  89. #endif
  90.